package com.ncloud.resman.mapper;

import java.util.List;
import java.util.Map;

import org.apache.ibatis.annotations.Insert;
import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Param;
import org.apache.ibatis.annotations.Result;
import org.apache.ibatis.annotations.Results;
import org.apache.ibatis.annotations.Select;
import org.apache.ibatis.annotations.Update;

import com.ncloud.resman.entity.SwitchModel;

@Mapper
public interface SwitchExtMapper {

	@Insert("insert into res_base_switch_ext(model_id,interface_num,i40g_num,update_date)"
			+ " values(#{modelId},#{interfaceNum},#{i40gNum},#{updateDate})")
	int insertSwitchModel(SwitchModel switchModel);

	@Select("select model_id,interface_num,i40g_num from res_base_switch_ext where model_id = #{modelId}")
	@Results({@Result(column="model_id",property="modelId"),@Result(column="interface_num",property="interfaceNum"),
		@Result(column="i40g_num",property="i40gNum")})
	SwitchModel getSwitchExtByModelId(Long modelId);

	@Update("update res_base_switch_ext set interface_num=#{interfaceNum},i40g_num=#{i40gNum},"
			+ " update_date=#{updateDate} where model_id = #{modelId}")
	void updateSwitchExt(SwitchModel switchExt);

	@Select("select a.eqpt_type as eqptType,c.brand_name brandName ,a.model_name modelName,"
			+ " a.eqpt_spec eqptSpec,b.interface_num interfaceNum,b.i40g_num i40gNum"
			+ " from res_base_model a,res_base_switch_ext b,res_base_brand c"
			+ " where a.model_id=b.model_id and a.eqpt_type=#{eqptType} "
			+ " and a.brand_id=ifnull(#{brandId},a.brand_id) and a.state ='1'"
			+ " and a.brand_id = c.brand_id")
	List<Map<String, Object>> getSwitchModesByEqptTypeAndBrandId(@Param("eqptType")String eqptType, @Param("brandId")Long brandId);

}
